//
//  HWTabBarItem.m
//  HW时光
//
//  Created by mac on 15/11/1.
//  Copyright © 2015年 tcf. All rights reserved.
//

#import "HWTabBarItem.h"
@implementation HWTabBarItem
{
    UIImageView *_imageView ;
    UILabel *_titleLable;
}
- (instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)name title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self != nil) {
        //创建子视图
    _imageView = [[UIImageView alloc]initWithFrame:CGRectMake((frame.size.width - 25)/2, 5, 25, 25)];
        _imageView.image = [UIImage imageNamed:name];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
        //创建标题视图
        CGFloat maxY = CGRectGetMaxY(_imageView.frame);
        _titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0, maxY, frame.size.width, 20)];
        _titleLable.text = title ;
        _titleLable.textColor = [UIColor lightGrayColor];
        _titleLable.textAlignment = NSTextAlignmentCenter;
        _titleLable.font = [UIFont systemFontOfSize:11];
        [self addSubview:_titleLable];
    }
    return self;
}


-(void)setSelected:(BOOL)selected sdName:(NSString *)sdName name:(NSString *)name
{
    [super setSelected:selected];
    if (selected == YES) {
        _imageView.image = [UIImage imageNamed:sdName];
        _titleLable.textColor = [UIColor colorWithRed:0 green:193/255.0  blue:173/255.0 alpha:1];
        
    }
    if (selected == NO) {
        _imageView.image = [UIImage imageNamed:name];
        _titleLable.textColor = [UIColor lightGrayColor];
    }
    
    
}

//if (self.selected == YES) {
//    titleLable.textColor = [UIColor colorWithRed:0 green:193/255.0  blue:173/255.0 alpha:1];
//}

@end
